﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Immunities
{
    public class ImmunityDelRequestHandler : IRequestHandler<ImmunityDelRequestModel, APIResult>
    {
        private readonly IBaseRepository<Immunity> immunityRepository;
        private readonly IMapper mapper;
        public ImmunityDelRequestHandler(IBaseRepository<Immunity> immunityRepository, IMapper mapper)
        {
            this.immunityRepository = immunityRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(ImmunityDelRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.DelSuccess;
            result.Msg = "删除成功";

            var res = immunityRepository.GetAll().FirstOrDefault(x=>x.Id == request.Id);
            if(res!=null)
            {
                res.IsDel= true;
                immunityRepository.Update(res);
            }


            return Task.FromResult(result);
        }
    }
    public class ImmunityDelRequestModel:IRequest<APIResult>
    {
        public int Id { get; set; }
    }
}
